package com.zsj.interceptor;

import com.zsj.util.IDGenerator;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description:
 * @Author:
 * @Date:
 */
@Slf4j
public class UidInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 健康检查
        if ("HEAD".equalsIgnoreCase(request.getMethod())) {
            // 如果是HEAD请求，则不执行拦截逻辑，直接返回true
            return true;
        }
        // log.info("生成日志id");
        // String selfUid = IDGenerator.getUUID();
        // MDC.put("selfUid", selfUid);
        // log.info("生成的日志id为:{}", selfUid);
        return true;
    }
}
